package xyz.renyumeng.xkm.shop.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import xyz.renyumeng.xkm.dto.shop.ProductInfoDto;
import xyz.renyumeng.xkm.model.es.EsProduct;
import xyz.renyumeng.xkm.model.shop.ProductInfo;
import xyz.renyumeng.xkm.result.Result;
import xyz.renyumeng.xkm.shop.service.ProductService;
import xyz.renyumeng.xkm.shop.service.UserProductService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author renyumeng
 * @date Created in 16:02 2023/6/30
 */


@Api(tags = "管理员商品信息接口")
@RestController
@RequestMapping("/admin/shop/product")
public class AdminProductController {

    @Resource
    private ProductService productService;

    @Resource
    private UserProductService userProductService;

    @GetMapping("/inner/{id}")
    public ProductInfo innerGetById(@PathVariable Long id) {
        return productService.getWithProDuct4OwnerDesc(id);
    }


    @PutMapping("/inner/{id}")
    public Boolean innerUpdateSoledInfoById(@PathVariable Long id){
        return productService.innerUpdateSoledInfoById(id);
    }

    @PutMapping("/inner/update")
    @ApiOperation(value = "修改一个商品信息")
    public Boolean updateProduct(@RequestBody ProductInfoDto productInfoDto) {
        return userProductService.upDateProduct(productInfoDto).getCode().equals(200);
    }

    @GetMapping("/inner/getAll")
    public List<EsProduct> getAll(){
        return productService.getAll();
    }

}
